const app = getApp()
var homeModel = require("../../model/homeModel.js")
var userUtil = require("../../utils/userUtil.js")
var util = require("../../utils/util.js")
var settingModel = require("../../model/settingModel.js")
Page({
  data: {
    data: {},
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    circular: true
  },
  onLoad: function(options) {
    userUtil.getUserInfo()
  },
  onShow: function() {
    this.init()
  },
  init() {
    var that = this
    if (app.data.user)
      settingModel.getCommentSetting(res => {
        if (res && res.status == 1 && res.compel == 1) {
          settingModel.noCommentCount(count => {
            if (count > 0)
              util.showModal('有待评价订单,是否前往', () => {
                wx.navigateTo({
                  url: '../user_order/user_order?index=3',
                })
              })
          })
        }
      })
    util.showLoading("加载中")
    homeModel.getRecommend(res => {
      wx.hideLoading()
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      wx.setNavigationBarTitle({
        title: res.data.homeName
      })
      that.setData({
        data: res.data
      })
    })
  },
  //商品详情
  navToInfo(e) {
    var data = e.currentTarget.dataset.data
    this.toGoodsInfo(data)
  },
  bindAd(e) {
    var data = e.currentTarget.dataset.data
    if (data.type == 1) {
      var obj = {
        id: data.productId,
        type: data.productType
      }
      this.toGoodsInfo(obj)
    }
  },
  toGoodsInfo(data) {
    var url
    if (data.type < 10)
      url = '../goods_info/goods_info?id=' + data.id + "&type=" + data.type
    else
      url = '../card_info/card_info?id=' + data.id + "&type=" + data.type
    wx.navigateTo({
      url: url
    })
  },
  //优惠券详情
  navToQuan(e) {
    app.data.quan = e.currentTarget.dataset.data
    wx.navigateTo({
      url: '../quan_info/quan_info',
    })
  },
  //拼团详情
  navToTuanInfo(e){
    var tuan = e.currentTarget.dataset.data
    app.data.tempTuan = e.currentTarget.dataset.data
    wx.navigateTo({
      url:"../tuan_info/tuan_info?sales="+tuan.sales
    })
  },
  navToClerk(e){
    app.data.clerk=e.currentTarget.dataset.data
    wx.navigateTo({
      url: '../clerk_info/clerk_info',
    })
  }
})